package org.dicr.radius;

import java.io.*;
import java.util.*;

import org.dicr.radius.dict.*;

/**
 * Radius Dictionary Interface
 *
 * @author <a href='http://dicr.org'>Igor (Dicr) Tarasov</a> {@literal <develop@dicr.org>}
 * @version 141025
 */
public interface RadiusDictionary {

	/**
	 * Search name of attribute vendor by code
	 *
	 * @param code vendor code
	 * @return vendor name or null if none
	 */
	String searchVendor(int code);

	/**
	 * Search vendor by name
	 * 
	 * @param name vendor name
	 * @return vendor code or null if not found
	 */
	Integer searchVendor(String name);

	/**
	 * Return list of all loaded vendors
	 * 
	 * @return vendors names
	 */
	Collection<String> listVendors();

	/**
	 * Search attribute description by it's codes
	 *
	 * @param vendor vendor code
	 * @param code attribute code
	 * @return attribute description or null if none
	 */
	AttributeDescriptor searchAttribute(int vendor, int code);

	/**
	 * Search attribute by it's name
	 *
	 * @param name attribute name
	 * @return attribute description
	 */
	AttributeDescriptor searchAttribute(String name);

	/**
	 * Attribute descriptor
	 */
	public static interface AttributeDescriptor extends Serializable, Cloneable, Comparable<AttributeDescriptor> {

		/**
		 * @return vendor code (0 .. {@value AbstractDictionary#VENDOR_MAX})
		 * @see AbstractDictionary#VENDOR_MAX
		 */
		int getVendor();

		/**
		 * Attribute code.<br>
		 * For simple RFC-attributes it's value is unsigned byte (0..256), but for other vendors its vary.
		 * 
		 * @return attribute code (0 .. {@value AbstractDictionary#CODE_MAX}) for non-vendor
		 * @see AbstractDictionary#CODE_MAX
		 */
		int getCode();

		/**
		 * @return name of attribute
		 */
		String getName();

		/**
		 * @return attribute value type
		 */
		ValueType getType();

		/**
		 * @return attribute value encoding
		 * @see <a href="http://freeradius.org/radiusd/man/dictionary.txt">Radius dictionary file</a>
		 */
		String getEncoding();

		/**
		 * Return named values of attribute
		 *
		 * @return map in which keys is value names, values is value data
		 */
		Map<String, Long> listValues();
	}
}
